<?php 
class PageAdmin extends Module{
	function PageAdmin($row){
		Module::Module($row);
		if(User::is_root()){
			$cmd=Url::get('cmd');
			
			switch ($cmd){
				case 'delete_all_cache':
					AZNet::update_all_page();
					require_once ROOT_PATH.'includes/enbac/dir.php';
					empty_all_dir(PAGE_CACHE_DIR,true);
					Url::redirect_current();
					break;
				case 'refresh':
					$id=(int)Url::get('id',0);
					if($id){
						AZNet::update_page($id);
				
						if(Url::check('href')){
							Url::redirect_url($_REQUEST['href']);
						}
						else{
							Url::redirect_current();
						}
					}
					Url::redirect_current();
					break;
				case 'delete':
					$id=(int)Url::get('id',0);
					if($id){
						DB::delete('block', 'page_id='.$id); 
						DB::delete_id('page', $id);
						require_once ROOT_PATH.'includes/enbac/dir.php';
						empty_all_dir(DIR_CACHE.'pages',true);
						empty_all_dir(DIR_CACHE.'modules',true);
					}
					
					Url::redirect_current();
					break;
				case 'edit':
				case 'add':
				case 'copy':
					require_once 'forms/edit.php';
					$this->add_form(new EditPageAdminForm());
					break;
				default: 
					require_once 'forms/list.php';
					$this->add_form(new ListPageAdminForm());
					break;
			}
		}
		else{
			Url::access_denied();
		}
	}
}
?>